package com.etalk.crm.serviceImpl;

import com.etalk.crm.dao.CCNewMainMapper;
import com.etalk.crm.pojo.NewMainBean;
import com.etalk.crm.service.CCNewMainService;
import com.etalk.crm.utils.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Jordan
 * @Auther: James
 * @Date: 2018/12/28 10:06
 * @Description: 课程顾问首页工作台
 */
@Service
public class CCNewMainServiceImpl implements CCNewMainService {
    @Resource
    private CCNewMainMapper ccNewMainMapper;

    @Override
    public PageInfo<NewMainBean> selectTrackRemindByUserId(Integer ccId, String searchDate, Integer sscId,Integer bccId, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        List<NewMainBean> list=ccNewMainMapper.selectTrackRemindByUserId(ccId,searchDate,sscId,bccId);
        if (list!=null && list.size()>0){
            for (NewMainBean newMainBean : list) {
                if (newMainBean.getReleaseTime().getTime() > DateUtil.getCurrentDatetime().getTime()) {
                    newMainBean.setExpired(0);
                } else {
                    newMainBean.setExpired(1);
                }
            }
        }
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<NewMainBean> searchStuOrderInfoByCC(int ccId, Integer sscId, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return new PageInfo<>(ccNewMainMapper.searchStuOrderInfoByUserId(ccId,sscId));
    }

    @Override
    public PageInfo<NewMainBean> demoMissedListByCC(int ccId, String searchDate, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return new PageInfo<>(ccNewMainMapper.demoMissedListByCC(ccId,searchDate));
    }

    @Override
    public PageInfo<NewMainBean> selectMainTipPotentialByCCId(int ccId,Integer state, Integer page, Integer size) {
        List<NewMainBean> list;
        Integer revisitId=0;
        if (state!=6){
            revisitId=ccNewMainMapper.selectParentIdById(state);
        }
        if (state==6 || revisitId==6){
            PageHelper.startPage(page, size);
            //查询已上可跟进(包含子类)的数据
            list=ccNewMainMapper.selectMainTipPotentialDemoTimeByCcId(ccId,state);
        }else {
            PageHelper.startPage(page, size);
            //查询非已上可跟进的数据
            list=ccNewMainMapper.selectMainTipPotentialByCCId(ccId,state);
        }
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<NewMainBean> selectMainTipRelLeadsByCC(int ccId, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return new PageInfo<>(ccNewMainMapper.selectMainTipRelLeadsByCC(ccId));
    }

    @Override
    public PageInfo<NewMainBean> selectMainTipNewStudentByCCId(int ccId, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return new PageInfo<>(ccNewMainMapper.selectMainTipNewStudentByCCId(ccId));
    }

    @Override
    public PageInfo<NewMainBean> selectOcInfoByCC(int ccId, Integer page, Integer size) {
        PageHelper.startPage(page, size);
        return new PageInfo<>(ccNewMainMapper.selectOcInfoByCC(ccId));
    }
}
